<%--
  Author      : MadFrog
  Date        : 2018/3/9 16:50
  Description : 问卷调查的首页
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>问卷调查</title>
    <%@include file="../common/_head.jsp"%>
</head>
<body ontouchstart>
<div class="weui-panel" id="questionnaire-panel-undo"></div>
<%@include file="../common/_foot.jsp"%>

<script type="text/javascript">
    $(function () {
        // 加载待完成的问卷
        $.ajax({
            type: "get",
            url: "${ctx}/student/questionnaire/listLatestByStudent",
            dataType: "json",
            success: function (re) {
                initUndo(re.data);
            },
            error: function () {
                $.toast("请完成当前题目", "cancel");
            }
        });
        // 渲染待完成的问卷
        function initUndo(qList) {
            // 渲染“未完成的测试”面板
            var undoPanel = $("#questionnaire-panel-undo");
            for (var i=0; i<qList.length; i++){
                var q = qList[i];
                var fullDate = new Date(q.closeDate);
                var operateStr;
                if(q.finishStatus=="FINISHED"){
                    operateStr = "已完成";
                }else{
                    operateStr = "<a href=\"${ctx}/student/subjectIndex/" + q.id + "\">开始问卷>></a>";
                }
                var closeDate = fullDate.getFullYear()+"-"+(fullDate.getMonth()+1)+"-"+fullDate.getDate();
                var mText =         "<div class=\"weui-media-box weui-media-box_text\">\n" +
                    "                    <h4 class=\"weui-media-box__title\">" + q.name + "</h4>\n" +
                    "                    <p class=\"weui-media-box__desc\">" + q.description + "</p>\n" +
                    "                    <ul class=\"weui-media-box__info\">\n" +
                    "                        <li class=\"weui-media-box__info__meta\">截止时间</li>\n" +
                    "                        <li class=\"weui-media-box__info__meta\">" + closeDate + "</li>\n" +
                    "                        <li class=\"weui-media-box__info__meta weui-media-box__info__meta_extra\">" + operateStr + "</li>\n"
                "                    </ul>\n" +
                "                </div>";
                undoPanel.append(mText);
            }
        }
    });
</script>

</body>
</html>